<?php
error_reporting(0);
$action=$_GET['action']; //站点目录
$url=$_GET['url']; //站点目录
?>
<? if($action=='ajaxlistinput'){ ?>
$(function(){
	//----------------列表和推荐值修改----------------------
	$(".TextTd").live("click", function() { // dblclick双击
		var _this=$(this);
		var value = _this.text();
		var id = _this.attr("rel");
		var isfresh = _this.attr("isfresh");
		var objName = _this.attr("name");
		var objPara = _this.attr("para");
		//var valueid = _this.next().text();
		if(value == "null") value = "";
		if(_this.find("input").length || id==""){return false;}
		_this.html("<input class=\"form-control TextBlur\" size=\"4\" name=\""+objName+"\" title=\""+value+"\" rel=\""+id+"\" isfresh=\""+isfresh+"\" para=\""+objPara+"\" value=\'"+value+"\' />");
		$(".TextBlur").focus();
	});
	$(".TextBlur").live("blur", function() { //失去焦点保存

		var _this=$(this);
		var objTitle=_this.attr("title");
        var objVal=_this.val();
		if(objTitle==objVal){_this.hide().parent("td").html(objVal);return false;}// 判断是否和原始数据相同
        ajaxData(_this);
		///*$.post("<?php //echo $url?>//",{id:objId,fieldName:objField,Val:objVal},function(result){
        //	//alert(result);
        //    if(result=="success"){
		//		_this.parent("td").html(objVal);
		//		_this.hide();
        //        if(objIsFresh==1){
        //            humane.success('修改完毕',function(){
        //                location.reload();
        //            });
        //        }else{
		//			humane.success('修改完毕');
        //        }
		//	}
		//});*/
	});
    
     //----------------select状态修改----------------------
	$("select.form-control.input-small").change(function() {
		var _this=$(this);
         _this.removeClass().addClass("form-control input-small select_color_"+_this.val());
		if(_this.val()==""){return false;}// 判断是否和原始数据相同
        ajaxData(_this);
	});
    
});
function ajaxData(_this){
    var objId=_this.attr("rel");
    var objField=_this.attr("name");
    var objPara=_this.attr("para");
    var objVal=_this.val();
	var objIsFresh=_this.attr("isfresh");
    $.post("<?=$url?>",{id:objId,fieldName:objField,Val:objVal},function(result){
    	//return result;
        if(result=="success"){
        
        	if(objPara=="input"){
                _this.parent("td").html(objVal);
                _this.hide();
            }
        
            if(objIsFresh==1){
                bootbox.dialog({
                    message: '修改完毕',
                    title: "",
                    buttons: {
                        success: {
                            label: "OK",
                            className: "green",
                            callback: function() {
                                //location.reload();
                            }
                        }
                    }
                });
            }else{
                bootbox.dialog({
                    message: '修改完成',
                    title: "",
                    buttons: {
                        success: {
                            label: "OK",
                            className: "blue",
                            callback: function() {
                                //location.reload();
                            }
                        }
                    }
                });
            }
        }else{
            bootbox.dialog({
                message: '修改失败',
                title: "",
                buttons: {
                    success: {
                        label: "OK",
                        className: "red",
                        callback: function() {
                            location.reload();
                        }
                    }
                }
            });
        }
    });
}
<? }?>
<? if($action=='ajaxPara'){  ?>
$(function(){
     //----------------select状态修改----------------------
	$(".selectPara").change(function() {
		var _this=$(this);
         _this.removeClass().addClass("select_color_"+_this.val());
		if(_this.val()==""){return false;}// 判断是否和原始数据相同
        ajaxParaData(_this);
        
	});
});
function ajaxParaData(_this){
	
    var objId=_this.attr("rel");//当前id
    //var objField=_this.attr("name"); //当前字段
    var objVal=_this.val();//当前选中的值
    var objpid=_this.attr("pid");//分类id
    $.post("<?=$url?>",{para_id:objId,pid:objpid,ParaType:objVal},function(result){
        if(result=="success"){
            humane.success('修改完毕',function(){
                location.reload();
            });
        }else if(result=="delok"){
            humane.info('删除成功',function(){
                location.reload();
            });
        }
        else{
            humane.error('修改失败',function(){
                location.reload();
            });
        }
    });
}
<? } ?>

/*
 *以下是根据新后台创建的ajax通用方法
 */
$('#submit').click(function(){
    $('#submit_form').ajaxSubmit({

        success: function (res) {

            bootbox.dialog({
                message: res.info,
                title: "",
                buttons: {
                    success: {
                        label: "OK",
                        className: (res.status == 1) ? "green" : "red",
                        callback: function () {
                            window.location.href = res.url;
                        }
                    }
                }
            });

        },
        error: function (XmlHttpRequest, textStatus, errorThrown) {
            console.log(errorThrown);
        },
        url: $('#submit_form').attr('action'), /*设置post提交到的页面*/
        type: 'post', /*设置表单以post方法提交*/
        resetForm: false
    });
});
/*Confirm ajax*/
var Confirm_ajax=function(url,message){
    data=arguments[2] ? arguments[2] : '';
    method=arguments[3] ? arguments[3] : 'get';
    bootbox.dialog({
        message: message,
        buttons: {
            success: {
                label: "Ok",
                className: "green",
                callback: function () {
                    $.ajax({

                        success: function (res) {

                            bootbox.alert(res.info, function() {
                                location.href=res.url
                            });

                        },
                        error: function (XmlHttpRequest, textStatus, errorThrown) {
                            console.log(errorThrown);
                        },
                        url: url,
                        type:method,
                        resetForm: false,
                        data:data
                    });
                }
            },
            error:{
                label:'Cancel',
                className:'default',

            }
        }
    });
}
/* a ajax*/
var A_ajax= function(url){
    data=arguments[2] ? arguments[2] : '';
    method=arguments[3] ? arguments[3] : 'get';
    $.ajax({

        success: function (res) {
            bootbox.alert(res.info, function() {
                location.href=res.url
            });

        },
        error: function (XmlHttpRequest, textStatus, errorThrown) {
            console.log(errorThrown);
        },
        url: url,
        type:method,
        resetForm: false,
        data:data
    });

}
